package org.homly.quartz;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.homly.sql.DbConfig;
import org.homly.sql.MySqlBackup;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;



public class BackUpDataBaseTask implements StatefulJob {
	private static Log log = LogFactory.getLog(BackUpDataBaseTask.class);     
    private static boolean isRunning = false;   
    private static String backUpUrl = "c:/test";
    public void execute(JobExecutionContext arg0) throws JobExecutionException {
    	// TODO Auto-generated method stub
    		if(!isRunning){
    			 log.debug("任务开始执行。。。"); //开始任务  
    			 System.out.println("start");
    			isRunning = true;
    			Date today = new Date();
    			try {
    				DbConfig config = new DbConfig();
    				config.setUserName("DIYPC");
    				config.setPassWord("DIYPC");
    				config.setDbName("diypc");
    				config.setPortNo("3306");
    				config.setIpNo("127.0.0.1");
    				config.setDbDriver("com.mysql.jdbc.Driver");
    				config.setDbType("mysql");
    				MySqlBackup back = new MySqlBackup(config);
    				back.createSqlScript(backUpUrl);
    				 System.out.println("end");
    			} catch (Exception e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    				log.debug("任务执行出错...");
    			} 
    			 log.debug("考试结束任务执行完成。。。"); //任务完成     
                 isRunning = false;    
    		}
    }
}
